﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NicoView.Speech.Learn;

namespace NicoView_Lib_UnitTest
{
    [TestClass]
    public class GeneralLearnModel_UnitTest
    {
        [TestMethod]
        public void Constractor()
        {
            GeneralLearnModel learnModel = new GeneralLearnModel();
            Assert.IsNull(learnModel.LearnDictionary);
        }

        [TestMethod]
        public void LearnTest()
        {
            var model = Create();
            model.Learn("test", "testValue");
            Assert.AreEqual(model.LearnDictionary["test"].Text, "testValue");
        }

        [TestMethod]
        public void OblivionTest()
        {
            var model = Create();
            model.Learn("test", "testValue");
            Assert.AreEqual(model.LearnDictionary["test"].Text, "testValue");
            model.Oblivion("test");
            Assert.IsFalse(model.LearnDictionary.ContainsKey("test"));
            

        }

        [TestMethod]
        public void ConvertLearnTest()
        {
            var model = Create();
            model.CheckTextCommand("教育(test=testValue)");
            Assert.IsTrue(model.LearnDictionary.ContainsKey("test"));
        }

        [TestMethod]
        public void ConvertLearnFailedTest()
        {
            var model = Create();
            model.CheckTextCommand(" 教育(test=testValue)");
            Assert.IsFalse(model.LearnDictionary.ContainsKey("test"));
        }
        

        [TestMethod]
        public void ConvertOblivionTest()
        {
            var model = Create();
            model.Learn("test", "testValue");
            model.CheckTextCommand("忘却(test)");
            Assert.IsFalse(model.LearnDictionary.ContainsKey("test"));
        }
        [TestMethod]
        public void ConvertOblivionFailedTest()
        {
            var model = Create();
            model.Learn("test", "testValue");
            model.CheckTextCommand(" 忘却(test)");
            Assert.IsTrue(model.LearnDictionary.ContainsKey("test"));
        }

        [TestMethod]
        public void ConvertTest()
        {
            var model = Create();
            model.Learn("test", "abc");
            model.Learn("あ", "んん");
            var convertResult = model.Convert("testあ");
            Assert.AreEqual(convertResult, "abcんん");
        }

        [TestMethod]
        public void ConvertTest2()
        {
            var model = Create();
            var convertResult = model.Convert("test???A（´・ω・｀）");
            Assert.AreEqual(convertResult, "test A ω");
        }

        [TestMethod]
        public void ConvertTest3()
        {
            var model = Create();
            model.CheckTextCommand("教育(（´・ω・｀）=しょぼん)");
            Assert.AreEqual(model.Convert("（´・ω・｀）"), "しょぼん");
        }

        [TestMethod]
        public void ConvertTest4()
        {
            var model = Create();
            var covrslt = model.CheckTextCommand("教育((´・ω・｀)=しょぼん)");
            var rslt = model.Convert("(´・ω・｀)");
            Assert.AreEqual(rslt, "しょぼん");
        }

        private GeneralLearnModel Create()
        {
            GeneralLearnModel model = new GeneralLearnModel();
            model.LearnDictionary = new LearnDictionary();
            model.RegexLearnDictionary = new RegexLearnDictionary();
            return model;
        }
    }
}
